package com.demo;


import com.coder4j.starter.generator.service.GeneratorService;
import com.coder4j.starter.generator.service.WebGeneratorService;
import com.coder4j.starter.generator.vo.CodeContentVO;
import com.coder4j.starter.generator.vo.TableParams;
import com.coder4j.starter.generator.vo.TemplateVO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.io.File;
import java.util.ArrayList;

@SpringBootTest
public class ApplicationTest {

    @Resource
    private GeneratorService service;

    @Test
    public void createAllWithBaseEntity(){
        String templatePath = "/Users/yangkaile/Projects/my/my_spring_helper/my_spring_platform/keller-platform-core/src/main/resources/template";
        String javaPath = "/Users/yangkaile/Projects/my/my_spring_helper/my_spring_platform/keller-demo-server/src/main/java/com/demo/a";
        String vuePath = "/Users/yangkaile/Projects/my/my_spring_helper/my_spring_platform/keller-demo-web/src";
        String author = "keller";
        TableParams tableParams = new TableParams(templatePath,javaPath,vuePath,author);
        tableParams.initTables(
                "sys_chinese_color:TblColor"
        );
        service.createJavaAndVue(tableParams);
    }

    @Resource
    private WebGeneratorService webGeneratorService;

    @Test
    public void generator(){
        String packageName = "com.keller";
        String userTempPath = "tongji";
        String[] tables = {"agv","agv_log"};

        for (String tableName : tables) {
            doGenerator(tableName,userTempPath,packageName);
        }

    }

    public void doGenerator(String tableName,String userTempPath,String packageName){
        TemplateVO template = webGeneratorService.initTemplate(tableName);
        template.setUserTempPath(userTempPath);
        template.setJavaPath(userTempPath + File.separator + "java");
        template.setVuePath(userTempPath + File.separator + "web");
        template.setSqlPath(userTempPath + File.separator + "sql");

        template.setGeneratorItems(new ArrayList<String>(){{
            add("java");
            add("vue");
            add("menu");
        }});

        template.setIconName("CarOutlined");
        template.setParentMenuId("138");
        template.setMenuName(template.getTableComment());
        template.setPackageName(packageName);

        webGeneratorService.generatorTempCode(template);

    }
}
